﻿using System;
using System.Collections.Generic;
using UnityEngine;
using XHFrame;

public class TestOneModule : BaseModule
{
    public int Gold { get; private set; }

    public TestOneModule()
    {
        this.AutoRegister = true;
    }
    protected override void OnLoad()
    {
        MessageCenter.Instance.AddListener(MessageType.Net_MessageTypeOne, UpdateGold);
        base.OnLoad();
    }

    protected override void OnRelease()
    {
        MessageCenter.Instance.RemoveListener(MessageType.Net_MessageTypeOne, UpdateGold);
        base.OnRelease();
    }

    private void UpdateGold(Message message)
    {
        int gold = (int)message["gold"];
        if (gold > 0)
        {
            Gold = gold;
            Message messages = new Message("AutoUpdateGold", this);
            messages["gold"] = Gold;
            messages.Send();
        }
    }
}
